<template>
  <div class="app-container">
    <div>
      <el-row class="admin-top-g">
        <br>

        <el-row class="common-row">
          <template v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length">
            <el-input v-model="keyword" clearable style="width: 260px;" placeholder="请输入关键字" @keyup.native.enter="searchUser" @change="searchUser"/>

            <!-- <el-date-picker
              v-model="fzhejiu"
              style="width: 145px;"
              type="year"

              placeholder="选择"
              @change="selectPeriod"/> -->

            <el-select v-model="fbrand" class="select_el" clearable filterable placeholder="请选择品牌" @change="searchUser">
              <el-option
                v-for="item2 in brandList"
                :key="item2.finterid"
                :label="item2.fname"
                :value="item2.fname"/>
            </el-select>

            <!--
            <el-select v-model="youqiVal" clearable filterable placeholder="请选择">
              <el-option
                v-for="item in youQiOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select> -->

            <el-button v-if="isBtn" type="danger" icon="el-icon-check" @click="calculate">计算</el-button>
            <el-button v-if="!isBtn && limits.length >= 1 && limits.filter(it => it.FName === '保存').length" type="success" icon="el-icon-news" @click="saveWage">保存</el-button>
            <el-button type="success" icon="el-icon-back" @click="back">返回</el-button>

          </template>

          <!-- <el-button type="primary" icon="el-icon-refresh" @click="refresh">刷新 </el-button> -->

        </el-row>
    </el-row></div>
    <br>
    <el-table
      v-loading="listLoading"
      v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
      :data="tableData"
      :header-cell-style="tableHeaderStyle"
      max-height="750"
      class="tableCss"
      element-loading-text="正在加载"
      border
      highlight-current-row
      @cell-dblclick="editData"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="selection"
        width="55"/>
      <template v-for="item in formThead">
        <el-table-column v-if="item.frpttypeflag ==0" :key="item.fid" :prop="item.frepfld" :label="item.frepcap" :width="item.frepwid" align="center" show-overflow-tooltip>

          <template slot-scope="scope">
            <template v-if="item.frephide<=0">
              <template v-if="item.frepfld === 'fstatus'">
                <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已审</el-tag>
                <el-tag v-else size="mini" type="danger">未审</el-tag>
              </template>
              <template v-else-if="item.frepfld === 'fisqr'">
                <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已完成</el-tag>
                <el-tag v-else size="mini" type="danger">未完成</el-tag>
              </template>
              <template v-else size="mini">
                {{ scope.row[item.frepfld] }}
              </template>
            </template>
          </template>

        </el-table-column>
      </template>
    </el-table>

    <el-dialog
      v-el-drag-dialog
      :visible.sync="detailSettings.fdetailModal"
      :close-on-click-modal="false"
      title="详情"
      class="config-dialog detail-dialog">
      <el-table
        v-loading="detailSettings.fdetailLoading"
        ref="fdetailTable"
        :header-cell-style="tableHeaderStyle"
        :data="detailSettings.fdetailData"
        style="margin-top: 10px;"
        max-height="500"
        class="tableCss"
        element-loading-text="正在加载"
        border
        highlight-current-row>
        <el-table-column
          v-for="(item, key) in detailSettings.detailFormThead"
          :key="key"
          :prop="item"
          :label="item"
          align="center">
          <template slot-scope="scope">{{ scope.row[item] }}</template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <el-dialog
      v-el-drag-dialog
      :visible.sync="jzcbdetailSettings.fdetailModal"
      :close-on-click-modal="false"
      title="详情"
      class="config-dialog detail-dialog">
      <el-table
        v-loading="jzcbdetailSettings.fdetailLoading"
        ref="fdetailTable"
        :header-cell-style="tableHeaderStyle"
        :data="jzcbdetailSettings.fdetailData"
        style="margin-top: 10px;"
        max-height="500"
        class="tableCss"
        element-loading-text="正在加载"
        border
        highlight-current-row>
        <el-table-column
          v-for="(item, key) in jzcbdetailSettings.detailFormThead"
          :key="key"
          :prop="item"
          :label="item"
          align="center">
          <template slot-scope="scope">{{ scope.row[item] }}</template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <el-dialog
      v-el-drag-dialog
      :visible.sync="zjrgDetailSettings.fdetailModal"
      :close-on-click-modal="false"
      :show-close="true"
      title="详情"
      class="cb-set-modal"
      width="50%">
      <div >
        <el-table
          v-loading="zjrgDetailSettings.fdetailLoading"
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          ref="cbTable"
          :data="zjrgDetailSettings.fdetailData"
          :header-cell-style="tableHeaderStyle"
          max-height="600"
          class="tableCss single-select-table"
          element-loading-text="正在加载"
          border
          highlight-current-row>
          <el-table-column
            type="selection"
            width="55"/>
          <template v-for="item in zjrgDetailSettings.detailFormThead">
            <el-table-column
              v-if="item.frpttypeflag ==0"
              :key="item.fid"
              :label="item.frepcap"
              :prop="item.frepfld"
              :width="item.frepwid"
              align="center"
              show-overflow-tooltip>

              <template slot-scope="scope">
                <template v-if="item.frephide<=0">
                  <template v-if="item.frepfld === 'fstatus'">
                    <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已审</el-tag>
                    <el-tag v-else size="mini" type="danger">未审</el-tag>
                  </template>
                  <template v-else size="mini">
                    {{ scope.row[item.frepfld] }}
                  </template>
                </template>
              </template>

            </el-table-column>
          </template>
        </el-table>

        <el-pagination
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          :total="zjrgDetailSettings.total"
          :page-sizes="zjrgDetailSettings.pagesizes"
          :page-size="zjrgDetailSettings.pagesize"
          :current-page.sync="zjrgDetailSettings.currentPage"
          class="jy-pagination"
          style="text-align: center; margin-top: 20px;"
          background
          layout="sizes, prev, pager, next, total"
          @size-change="zJHandleSizeChange"
          @current-change="zJHandleCurrentChange"/>
      </div>
    </el-dialog>

    <el-dialog
      v-el-drag-dialog
      :visible.sync="sdDetailSettings.fdetailModal"
      :close-on-click-modal="false"
      :show-close="true"
      title="详情"
      class="cb-set-modal"
      width="50%">
      <div >
        <el-table
          v-loading="sdDetailSettings.fdetailLoading"
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          ref="cbTable"
          :data="sdDetailSettings.fdetailData"
          :header-cell-style="tableHeaderStyle"
          max-height="600"
          class="tableCss single-select-table"
          element-loading-text="正在加载"
          border
          highlight-current-row>
          <el-table-column
            type="selection"
            width="55"/>
          <template v-for="item in sdDetailSettings.detailFormThead">
            <el-table-column
              v-if="item.frpttypeflag ==0"
              :key="item.fid"
              :label="item.frepcap"
              :prop="item.frepfld"
              :width="item.frepwid"
              align="center"
              show-overflow-tooltip>

              <template slot-scope="scope">
                <template v-if="item.frephide<=0">
                  <template v-if="item.frepfld === 'fstatus'">
                    <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已审</el-tag>
                    <el-tag v-else size="mini" type="danger">未审</el-tag>
                  </template>
                  <template v-else size="mini">
                    {{ scope.row[item.frepfld] }}
                  </template>
                </template>
              </template>

            </el-table-column>
          </template>
        </el-table>

        <el-pagination
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          :total="sdDetailSettings.total"
          :page-sizes="sdDetailSettings.pagesizes"
          :page-size="sdDetailSettings.pagesize"
          :current-page.sync="sdDetailSettings.currentPage"
          class="jy-pagination"
          style="text-align: center; margin-top: 20px;"
          background
          layout="sizes, prev, pager, next, total"
          @size-change="sDHandleSizeChange"
          @current-change="sDHandleCurrentChange"/>
      </div>
    </el-dialog>

    <el-dialog
      v-el-drag-dialog
      :visible.sync="shDetailSettings.fdetailModal"
      :close-on-click-modal="false"
      :show-close="true"
      title="详情"
      class="cb-set-modal"
      width="50%">
      <div >
        <el-table
          v-loading="shDetailSettings.fdetailLoading"
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          ref="cbTable"
          :data="shDetailSettings.fdetailData"
          :header-cell-style="tableHeaderStyle"
          max-height="600"
          class="tableCss single-select-table"
          element-loading-text="正在加载"
          border
          highlight-current-row>
          <el-table-column
            type="selection"
            width="55"/>
          <template v-for="item in shDetailSettings.detailFormThead">
            <el-table-column
              v-if="item.frpttypeflag ==0"
              :key="item.fid"
              :label="item.frepcap"
              :prop="item.frepfld"
              :width="item.frepwid"
              align="center"
              show-overflow-tooltip>
              <template slot-scope="scope">
                <template v-if="item.frephide<=0">
                  <template v-if="item.frepfld === 'fstatus'">
                    <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已审</el-tag>
                    <el-tag v-else size="mini" type="danger">未审</el-tag>
                  </template>
                  <template v-else size="mini">
                    {{ scope.row[item.frepfld] }}
                  </template>
                </template>
              </template>
            </el-table-column>
          </template>
        </el-table>
        <el-pagination
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          :total="shDetailSettings.total"
          :page-sizes="shDetailSettings.pagesizes"
          :page-size="shDetailSettings.pagesize"
          :current-page.sync="shDetailSettings.currentPage"
          class="jy-pagination"
          style="text-align: center; margin-top: 20px;"
          background
          layout="sizes, prev, pager, next, total"
          @size-change="shHandleSizeChange"
          @current-change="shHandleCurrentChange"/>
      </div>
    </el-dialog>

    <el-dialog
      v-el-drag-dialog
      :visible.sync="zlcbDetailSettings.fdetailModal"
      :close-on-click-modal="false"
      :show-close="true"
      title="详情"
      class="cb-set-modal"
      width="50%">
      <div >
        <el-table
          v-loading="zlcbDetailSettings.fdetailLoading"
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          ref="cbTable"
          :data="zlcbDetailSettings.fdetailData"
          :header-cell-style="tableHeaderStyle"
          max-height="600"
          class="tableCss single-select-table"
          element-loading-text="正在加载"
          border
          highlight-current-row>
          <el-table-column
            type="selection"
            width="55"/>
          <template v-for="item in zlcbDetailSettings.detailFormThead">
            <el-table-column
              v-if="item.frpttypeflag ==0"
              :key="item.fid"
              :label="item.frepcap"
              :prop="item.frepfld"
              :width="item.frepwid"
              align="center"
              show-overflow-tooltip>
              <template slot-scope="scope">
                <template v-if="item.frephide<=0">
                  <template v-if="item.frepfld === 'fstatus'">
                    <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已审</el-tag>
                    <el-tag v-else size="mini" type="danger">未审</el-tag>
                  </template>
                  <template v-else size="mini">
                    {{ scope.row[item.frepfld] }}
                  </template>
                </template>
              </template>
            </el-table-column>
          </template>
        </el-table>
        <el-pagination
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          :total="zlcbDetailSettings.total"
          :page-sizes="zlcbDetailSettings.pagesizes"
          :page-size="zlcbDetailSettings.pagesize"
          :current-page.sync="zlcbDetailSettings.currentPage"
          class="jy-pagination"
          style="text-align: center; margin-top: 20px;"
          background
          layout="sizes, prev, pager, next, total"
          @size-change="zlcbHandleSizeChange"
          @current-change="zlcbHandleCurrentChange"/>
      </div>
    </el-dialog>

    <el-dialog
      v-el-drag-dialog
      :visible.sync="wwfyDetailSettings.fdetailModal"
      :close-on-click-modal="false"
      :show-close="true"
      title="详情"
      class="cb-set-modal"
      width="50%">
      <div >
        <el-table
          v-loading="wwfyDetailSettings.fdetailLoading"
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          ref="cbTable"
          :data="wwfyDetailSettings.fdetailData"
          :header-cell-style="tableHeaderStyle"
          max-height="600"
          class="tableCss single-select-table"
          element-loading-text="正在加载"
          border
          highlight-current-row>
          <el-table-column
            type="selection"
            width="55"/>
          <template v-for="item in wwfyDetailSettings.detailFormThead">
            <el-table-column
              v-if="item.frpttypeflag ==0"
              :key="item.fid"
              :label="item.frepcap"
              :prop="item.frepfld"
              :width="item.frepwid"
              align="center"
              show-overflow-tooltip>
              <template slot-scope="scope">
                <template v-if="item.frephide<=0">
                  <template v-if="item.frepfld === 'fstatus'">
                    <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已审</el-tag>
                    <el-tag v-else size="mini" type="danger">未审</el-tag>
                  </template>
                  <template v-else size="mini">
                    {{ scope.row[item.frepfld] }}
                  </template>
                </template>
              </template>
            </el-table-column>
          </template>
        </el-table>
        <el-pagination
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          :total="wwfyDetailSettings.total"
          :page-sizes="wwfyDetailSettings.pagesizes"
          :page-size="wwfyDetailSettings.pagesize"
          :current-page.sync="wwfyDetailSettings.currentPage"
          class="jy-pagination"
          style="text-align: center; margin-top: 20px;"
          background
          layout="sizes, prev, pager, next, total"
          @size-change="wwfyHandleSizeChange"
          @current-change="wwfyHandleCurrentChange"/>
      </div>
    </el-dialog>

    <el-dialog
      v-el-drag-dialog
      :visible.sync="tzfDetailSettings.fdetailModal"
      :close-on-click-modal="false"
      :show-close="true"
      title="详情"
      class="cb-set-modal"
      width="50%">
      <div >
        <el-table
          v-loading="tzfDetailSettings.fdetailLoading"
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          ref="cbTable"
          :data="tzfDetailSettings.fdetailData"
          :header-cell-style="tableHeaderStyle"
          max-height="600"
          class="tableCss single-select-table"
          element-loading-text="正在加载"
          border
          highlight-current-row>
          <el-table-column
            type="selection"
            width="55"/>
          <template v-for="item in tzfDetailSettings.detailFormThead">
            <el-table-column
              v-if="item.frpttypeflag ==0"
              :key="item.fid"
              :label="item.frepcap"
              :prop="item.frepfld"
              :width="item.frepwid"
              align="center"
              show-overflow-tooltip>
              <template slot-scope="scope">
                <template v-if="item.frephide<=0">
                  <template v-if="item.frepfld === 'fstatus'">
                    <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已审</el-tag>
                    <el-tag v-else size="mini" type="danger">未审</el-tag>
                  </template>
                  <template v-else size="mini">
                    {{ scope.row[item.frepfld] }}
                  </template>
                </template>
              </template>
            </el-table-column>
          </template>
        </el-table>
        <el-pagination
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          :total="tzfDetailSettings.total"
          :page-sizes="tzfDetailSettings.pagesizes"
          :page-size="tzfDetailSettings.pagesize"
          :current-page.sync="tzfDetailSettings.currentPage"
          class="jy-pagination"
          style="text-align: center; margin-top: 20px;"
          background
          layout="sizes, prev, pager, next, total"
          @size-change="tzfHandleSizeChange"
          @current-change="tzfHandleCurrentChange"/>
      </div>
    </el-dialog>

    <el-dialog
      v-el-drag-dialog
      :visible.sync="tdgzDetailSettings.fdetailModal"
      :close-on-click-modal="false"
      :show-close="true"
      title="详情"
      class="cb-set-modal"
      width="50%">
      <div >
        <el-table
          v-loading="tdgzDetailSettings.fdetailLoading"
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          ref="cbTable"
          :data="tdgzDetailSettings.fdetailData"
          :header-cell-style="tableHeaderStyle"
          max-height="600"
          class="tableCss single-select-table"
          element-loading-text="正在加载"
          border
          highlight-current-row>
          <el-table-column
            type="selection"
            width="55"/>
          <template v-for="item in tdgzDetailSettings.detailFormThead">
            <el-table-column
              v-if="item.frpttypeflag ==0"
              :key="item.fid"
              :label="item.frepcap"
              :prop="item.frepfld"
              :width="item.frepwid"
              align="center"
              show-overflow-tooltip>
              <template slot-scope="scope">
                <template v-if="item.frephide<=0">
                  <template v-if="item.frepfld === 'fstatus'">
                    <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已审</el-tag>
                    <el-tag v-else size="mini" type="danger">未审</el-tag>
                  </template>
                  <template v-else size="mini">
                    {{ scope.row[item.frepfld] }}
                  </template>
                </template>
              </template>
            </el-table-column>
          </template>
        </el-table>
        <el-pagination
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          :total="tdgzDetailSettings.total"
          :page-sizes="tdgzDetailSettings.pagesizes"
          :page-size="tdgzDetailSettings.pagesize"
          :current-page.sync="tdgzDetailSettings.currentPage"
          class="jy-pagination"
          style="text-align: center; margin-top: 20px;"
          background
          layout="sizes, prev, pager, next, total"
          @size-change="tdgzHandleSizeChange"
          @current-change="tdgzHandleCurrentChange"/>
      </div>
    </el-dialog>

    <el-dialog
      v-el-drag-dialog
      :visible.sync="tddjDetailSettings.fdetailModal"
      :close-on-click-modal="false"
      :show-close="true"
      title="详情"
      class="cb-set-modal"
      width="50%">
      <div >
        <el-table
          v-loading="tddjDetailSettings.fdetailLoading"
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          ref="cbTable"
          :data="tddjDetailSettings.fdetailData"
          :header-cell-style="tableHeaderStyle"
          max-height="600"
          class="tableCss single-select-table"
          element-loading-text="正在加载"
          border
          highlight-current-row>
          <el-table-column
            type="selection"
            width="55"/>
          <template v-for="item in tddjDetailSettings.detailFormThead">
            <el-table-column
              v-if="item.frpttypeflag ==0"
              :key="item.fid"
              :label="item.frepcap"
              :prop="item.frepfld"
              :width="item.frepwid"
              align="center"
              show-overflow-tooltip>
              <template slot-scope="scope">
                <template v-if="item.frephide<=0">
                  <template v-if="item.frepfld === 'fstatus'">
                    <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已审</el-tag>
                    <el-tag v-else size="mini" type="danger">未审</el-tag>
                  </template>
                  <template v-else size="mini">
                    {{ scope.row[item.frepfld] }}
                  </template>
                </template>
              </template>
            </el-table-column>
          </template>
        </el-table>
        <br>
        <el-pagination
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          :total="tddjDetailSettings.total"
          :page-sizes="tddjDetailSettings.pagesizes"
          :page-size="tddjDetailSettings.pagesize"
          :current-page.sync="tddjDetailSettings.currentPage"
          class="jy-pagination"
          style="text-align: center; margin-top: 20px;"
          background
          layout="sizes, prev, pager, next, total"
          @size-change="tddjHandleSizeChange"
          @current-change="tddjHandleCurrentChange"/>
      </div>
    </el-dialog>

  </div>
</template>
<script>
let FRepKey = ''
let opername = ''
const defaultFormThead = []

import HeadTable from '../salary/headTable/index.vue'
import { configColumn, JZBaojiaSave, JZbaojiadan } from '../../api/salary'
import { download } from '../../mixins/download.js'
import { common } from '../../mixins/common'
import { brand } from '../../mixins/brand'
import { pagination } from '../../mixins/pagination'
import { parseTime, getYearYYYY } from '../../utils/index'
import { tableConfig, apiSql, apiFileSave, getCBData } from '../../api/account'
import { genList } from '../../api/gen'

import '../../styles/common.scss'

export default {
  name: 'Index',
  components: {
    HeadTable
  },
  filters: {
    parseTime(time, type) {
      return parseTime(time, type)
    }
  },
  mixins: [download, common, pagination, brand],
  data() {
    return {
      isBtn: true,
      value: '',
      options: [],
      FRepKey: '',
      keyword: '',
      fzhejiu: '',
      fdeleted: '',
      fdeletedList: [

      ],
      youQiOptions: [{
        value: '0',
        label: '经营报价'
      }, {
        value: '1',
        label: '合同报价'
      }],
      youqiVal: '0',

      fdeletedListDiaL: [

      ],
      gapTime: '',
      start_time: '',
      end_time: '',

      // 表头、表格设置
      tableData: [],
      tableList: [],
      defaultFormThead: [],
      formThead: defaultFormThead,
      dialogThead: [],
      curData: {},

      listLoading: false,
      list: [],
      configModal: false,
      configLoading: false,

      loadingForm: false,
      configList: [],
      key: 0,
      // SQL弹窗
      dialogSQLModal: false,
      loadingFormSQL: false,
      formSQL: {
        gzsql: ''
      },
      rulesSQL: {

      },

      form: {},
      rules: {

      },
      addUserModal: false,
      // loadingForm: false

      fileList: [],

      // 批量删除
      checkData: [],
      selectedData: [],
      rows: [],

      // 用户菜单
      menusList: [],
      limits: [],
      userKey: '',
      fmofanName: '',

      upData: {},
      fdeptname: '', // 部门
      bmList: [], // 部门
      xlList: [], // 学历
      zwList: [], // 职务
      xbList: [], // 性别
      lzztList: [],
      fileListBasic: [],
      baseList: [],
      upDataBasic: {},

      // 单台直接材料(不含税)明细
      detailSettings: {
        fmodel: '',
        fbrand: '',
        fbrandList: [
          { label: 'WINGD', value: 'WINGD' },
          { label: 'MAN', value: 'MAN' }
        ],
        fdanweibumen: '0',
        fdanweibumenList: [
          { label: '采购部', value: '1' },
          { label: '技术中心', value: '2' },
          { label: '其他部门', value: '3' },
          { label: '全部', value: '0' }
        ],
        keyword: '',
        fdetailModal: false,
        fdetailKeyword: '',
        fdetailLoading: false,
        detailFormThead: [],
        fdetailData: [],
        // 页脚
        total: 0,
        pagesize: 10,
        pagesizes: [10, 20, 50, 100],
        currentPage: 1
      },

      // 加账成本
      jzcbdetailSettings: {
        fmodel: '',
        fbrand: '',
        fbrandList: [
          { label: 'WINGD', value: 'WINGD' },
          { label: 'MAN', value: 'MAN' }
        ],
        fdanweibumen: '0',
        fdanweibumenList: [
          { label: '采购部', value: '1' },
          { label: '技术中心', value: '2' },
          { label: '其他部门', value: '3' },
          { label: '全部', value: '0' }
        ],
        keyword: '',
        fdetailModal: false,
        fdetailKeyword: '',
        fdetailLoading: false,
        detailFormThead: [],
        fdetailData: [],
        // 页脚
        total: 0,
        pagesize: 10,
        pagesizes: [10, 20, 50, 100],
        currentPage: 1,
        FRepKey: 26009
      },

      // 水电费合计
      sdDetailSettings: {
        header: [], // 表头字段（值）
        headerKeys: [], // 表头字段（键） filterVal
        listData: [], // 表体数据
        fmodel: '',
        fbrand: 'WINGD',
        fbrandList: [
          { label: 'WINGD', value: 'WINGD' },
          { label: 'MAN', value: 'MAN' }
        ],
        fdanweibumen: '0',
        fdanweibumenList: [
          { label: '采购部', value: '1' },
          { label: '技术中心', value: '2' },
          { label: '其他部门', value: '3' },
          { label: '全部', value: '0' }
        ],
        // keyword: '',
        fdetailModal: false, // 1
        fdetailKeyword: '', // 1
        fdetailLoading: false, // 1
        detailFormThead: [], // 1
        detailDialogThead: [],
        fdetailData: [], // 1
        fdetailList: [],
        // 页脚
        total: 0,
        pagesize: 10,
        pagesizes: [10, 20, 50, 100],
        currentPage: 1
      },

      // 售后成本
      shDetailSettings: {
        header: [], // 表头字段（值）
        headerKeys: [], // 表头字段（键） filterVal
        listData: [], // 表体数据
        fmodel: '',
        fbrand: 'WINGD',
        fbrandList: [
          { label: 'WINGD', value: 'WINGD' },
          { label: 'MAN', value: 'MAN' }
        ],
        fdanweibumen: '0',
        fdanweibumenList: [
          { label: '采购部', value: '1' },
          { label: '技术中心', value: '2' },
          { label: '其他部门', value: '3' },
          { label: '全部', value: '0' }
        ],
        // keyword: '',
        fdetailModal: false, // 1
        fdetailKeyword: '', // 1
        fdetailLoading: false, // 1
        detailFormThead: [], // 1
        detailDialogThead: [],
        fdetailData: [], // 1
        fdetailList: [],
        // 页脚
        total: 0,
        pagesize: 10,
        pagesizes: [10, 20, 50, 100],
        currentPage: 1
      },

      // 质量成本(交付前)
      zlcbDetailSettings: {
        header: [], // 表头字段（值）
        headerKeys: [], // 表头字段（键） filterVal
        listData: [], // 表体数据
        fmodel: '',
        fbrand: 'WINGD',
        fbrandList: [
          { label: 'WINGD', value: 'WINGD' },
          { label: 'MAN', value: 'MAN' }
        ],
        fdanweibumen: '0',
        fdanweibumenList: [
          { label: '采购部', value: '1' },
          { label: '技术中心', value: '2' },
          { label: '其他部门', value: '3' },
          { label: '全部', value: '0' }
        ],
        // keyword: '',
        fdetailModal: false, // 1
        fdetailKeyword: '', // 1
        fdetailLoading: false, // 1
        detailFormThead: [], // 1
        detailDialogThead: [],
        fdetailData: [], // 1
        fdetailList: [],
        // 页脚
        total: 0,
        pagesize: 10,
        pagesizes: [10, 20, 50, 100],
        currentPage: 1,
        FRepKey: 26013
      },

      // 委外费用
      wwfyDetailSettings: {
        header: [], // 表头字段（值）
        headerKeys: [], // 表头字段（键） filterVal
        listData: [], // 表体数据
        fmodel: '',
        fbrand: 'WINGD',
        fbrandList: [
          { label: 'WINGD', value: 'WINGD' },
          { label: 'MAN', value: 'MAN' }
        ],
        fdanweibumen: '0',
        fdanweibumenList: [
          { label: '采购部', value: '1' },
          { label: '技术中心', value: '2' },
          { label: '其他部门', value: '3' },
          { label: '全部', value: '0' }
        ],
        // keyword: '',
        fdetailModal: false, // 1
        fdetailKeyword: '', // 1
        fdetailLoading: false, // 1
        detailFormThead: [], // 1
        detailDialogThead: [],
        fdetailData: [], // 1
        fdetailList: [],
        // 页脚
        total: 0,
        pagesize: 10,
        pagesizes: [10, 20, 50, 100],
        currentPage: 1,
        FRepKey: 26014
      },

      // 图纸费
      tzfDetailSettings: {
        header: [], // 表头字段（值）
        headerKeys: [], // 表头字段（键） filterVal
        listData: [], // 表体数据
        fmodel: '',
        fbrand: 'WINGD',
        fbrandList: [
          { label: 'WINGD', value: 'WINGD' },
          { label: 'MAN', value: 'MAN' }
        ],
        fdanweibumen: '0',
        fdanweibumenList: [
          { label: '采购部', value: '1' },
          { label: '技术中心', value: '2' },
          { label: '其他部门', value: '3' },
          { label: '全部', value: '0' }
        ],
        // keyword: '',
        fdetailModal: false, // 1
        fdetailKeyword: '', // 1
        fdetailLoading: false, // 1
        detailFormThead: [], // 1
        detailDialogThead: [],
        fdetailData: [], // 1
        fdetailList: [],
        // 页脚
        total: 0,
        pagesize: 10,
        pagesizes: [10, 20, 50, 100],
        currentPage: 1,
        FRepKey: 26015
      },

      // 特定工装
      tdgzDetailSettings: {
        header: [], // 表头字段（值）
        headerKeys: [], // 表头字段（键） filterVal
        listData: [], // 表体数据
        fmodel: '',
        fbrand: 'WINGD',
        fbrandList: [
          { label: 'WINGD', value: 'WINGD' },
          { label: 'MAN', value: 'MAN' }
        ],
        fdanweibumen: '0',
        fdanweibumenList: [
          { label: '采购部', value: '1' },
          { label: '技术中心', value: '2' },
          { label: '其他部门', value: '3' },
          { label: '全部', value: '0' }
        ],
        // keyword: '',
        fdetailModal: false, // 1
        fdetailKeyword: '', // 1
        fdetailLoading: false, // 1
        detailFormThead: [], // 1
        detailDialogThead: [],
        fdetailData: [], // 1
        fdetailList: [],
        // 页脚
        total: 0,
        pagesize: 10,
        pagesizes: [10, 20, 50, 100],
        currentPage: 1,
        FRepKey: 26017
      },

      // 特定刀具
      tddjDetailSettings: {
        header: [], // 表头字段（值）
        headerKeys: [], // 表头字段（键） filterVal
        listData: [], // 表体数据
        fmodel: '',
        fbrand: 'WINGD',
        fbrandList: [
          { label: 'WINGD', value: 'WINGD' },
          { label: 'MAN', value: 'MAN' }
        ],
        fdanweibumen: '0',
        fdanweibumenList: [
          { label: '采购部', value: '1' },
          { label: '技术中心', value: '2' },
          { label: '其他部门', value: '3' },
          { label: '全部', value: '0' }
        ],
        // keyword: '',
        fdetailModal: false, // 1
        fdetailKeyword: '', // 1
        fdetailLoading: false, // 1
        detailFormThead: [], // 1
        detailDialogThead: [],
        fdetailData: [], // 1
        fdetailList: [],
        // 页脚
        total: 0,
        pagesize: 10,
        pagesizes: [10, 20, 50, 100],
        currentPage: 1,
        FRepKey: 26018
      },

      // 直接人工明细
      zjrgDetailSettings: {
        header: [], // 表头字段（值）
        headerKeys: [], // 表头字段（键） filterVal
        listData: [], // 表体数据
        fmodel: '',
        fbrand: 'WINGD',
        fbrandList: [
          { label: 'WINGD', value: 'WINGD' },
          { label: 'MAN', value: 'MAN' }
        ],
        fdanweibumen: '0',
        fdanweibumenList: [
          { label: '采购部', value: '1' },
          { label: '技术中心', value: '2' },
          { label: '其他部门', value: '3' },
          { label: '全部', value: '0' }
        ],
        // keyword: '',
        fdetailModal: false, // 1
        fdetailKeyword: '', // 1
        fdetailLoading: false, // 1
        detailFormThead: [], // 1
        detailDialogThead: [],
        fdetailData: [], // 1
        fdetailList: [],
        // 页脚
        total: 0,
        pagesize: 10,
        pagesizes: [10, 20, 50, 100],
        currentPage: 1
      },

      detail: '',
      opername: '',
      detailVisible: false,
      editText: false,
      tableSetExcel: false,
      lookSetShow: false

    }
  },
  async mounted() {
    this.userKey = this.$route.meta.FRepKey
    FRepKey = this.$route.meta.FRepKey
    this.upDataBasic.db = this.globalDb.db
    opername = decodeURIComponent(this.globalDb.fname)
    this.opername = decodeURIComponent(this.globalDb.fname)

    this.upDataBasic.FRepKey = this.$route.meta.FRepKey
    this.lookSetShow = JSON.parse(localStorage.getItem('flookSet'))

    this.upData.db = this.globalDb.db
    this.fmofanName = this.$route.meta.title

    await this.getAllData()

    // 菜单列表（权限）
    const menuRes = JSON.parse(localStorage.getItem('setMenuData'))
    this.menusList = menuRes
    if (menuRes.length >= 1) {
      menuRes.map(it => {
        it.children.map(item => {
          if (item.fobjectid === this.userKey) {
            this.$set(this, 'limits', item.child)
          }
        })
      })
    }
  },
  methods: {
    async detailSizeChange(val) {
      this.detailSettings.currentPage = 1
      this.detailSettings.pagesize = val
      await this.getCBDataList()
    },
    async detailCurrentChange(val) {
      this.detailSettings.currentPage = val
      await this.getCBDataList()
    },
    async searchFmodel() {
      await this.getCBDataList()
    },
    async getCBDataList() {
      try {
        this.detailSettings.fdetailLoading = true
        const res = await getCBData({
          db: this.globalDb.db,
          opername,
          fmodel: this.detailSettings.fmodel,
          fbrand: this.detailSettings.fbrand,
          keyword: this.detailSettings.keyword,
          fdanweibumen: this.detailSettings.fdanweibumen,
          // FRepKey: 26009
          all: 1
          // $fmodel =   $request ->fmodel;
          // $fbrand = $request ->fbrand??'WINGD';
          // $keyword =   $request ->keyword;
          // $fdanweibumen = $request ->fdanweibumen;
          // $FRepKey = $request ->FRepKey;
        })
        if (res.Error === 0) {
          if (res.Data.length) {
            this.detailSettings.detailFormThead = Object.keys(res.Data[0])
          } else {
            this.detailSettings.detailFormThead = []
          }
          setTimeout(() => {
            this.detailSettings.fdetailData = res.Data
          }, 0)
          // console.log(this.formThead, ' this.formThead')
        }
        // this.key = FRepKey
        this.detailSettings.fdetailLoading = false
      } catch (error) {
        this.detailSettings.fdetailLoading = false
      }
    },
    // 加账成本
    async getJzcbCBDataList() {
      try {
        this.jzcbdetailSettings.fdetailLoading = true
        const res = await getCBData({
          db: this.globalDb.db,
          opername,
          fmodel: this.jzcbdetailSettings.fmodel,
          fbrand: this.jzcbdetailSettings.fbrand,
          keyword: this.jzcbdetailSettings.keyword,
          fdanweibumen: '',
          all: 2
        })
        if (res.Error === 0 && res.Data.length) {
          this.jzcbdetailSettings.detailFormThead = Object.keys(res.Data[0])
          setTimeout(() => {
            this.jzcbdetailSettings.fdetailData = res.Data
          }, 0)
          // console.log(this.formThead, ' this.formThead')
        }
        // this.key = FRepKey
        this.jzcbdetailSettings.fdetailLoading = false
      } catch (error) {
        this.jzcbdetailSettings.fdetailLoading = false
      }
    },
    async editData(row, column, cell, event) {
      // fnotaxsinglezjcl  单台直接材料(不含税)
      console.log(column.id, column.property, column, row, event, 'column')
      if (column.property === 'fnotaxsinglezjcl') {
        this.detailSettings.fmodel = row.fmodel
        this.detailSettings.fbrand = row.fbrand
        this.detailSettings.fdetailModal = true
        await this.getCBDataList()
      }

      //  0 - 默认 不管  ,1-- 采购成本 ，2 -- 加账成本 ，不要FRepKey  仅针对加账和采购， zlc caculateCb页面
      // 加账成本 fjiazhangcb
      if (column.property === 'fjiazhangcb') {
        this.jzcbdetailSettings.fmodel = row.fmodel
        this.jzcbdetailSettings.fbrand = row.fbrand
        this.jzcbdetailSettings.fdetailModal = true
        await this.getJzcbCBDataList()
      }
      // 、、、、、、、、、、、、
      // 水电费        fsdtotal    水电费合计
      if (column.property === 'fsdtotal') {
        this.sdDetailSettings.fmodel = row.fmodel
        this.sdDetailSettings.fdetailModal = true
        await this.getSdBodyData()
        await this.getSdHeadData()
      }
      // 售后调试及维护成本 fsalecost  售后成本
      if (column.property === 'fsalecost') {
        this.shDetailSettings.fmodel = row.fmodel
        this.shDetailSettings.fdetailModal = true
        await this.getShBodyData()
        await this.getShHeadData()
      }
      // 质量成本     fqualitycost 质量成本(交付前)
      if (column.property === 'fqualitycost') {
        this.zlcbDetailSettings.fmodel = row.fmodel
        this.zlcbDetailSettings.fdetailModal = true
        await this.getZlcbBodyData()
        await this.getZlcbHeadData()
      }
      // 委外费用     fweiwaifee   委外费用
      if (column.property === 'fweiwaifee') {
        this.wwfyDetailSettings.fmodel = row.fmodel
        this.wwfyDetailSettings.fdetailModal = true
        await this.getWwfyBodyData()
        await this.getWwfyHeadData()
      }
      // 图纸费       fdrawingfee  图纸费
      if (column.property === 'fdrawingfee') {
        this.tzfDetailSettings.fmodel = row.fmodel
        this.tzfDetailSettings.fdetailModal = true
        await this.getTzfBodyData()
        await this.getTzfHeadData()
      }
      // 特定工装 特定工装-整体发运 fworkwhole  特定工装-分体发运   fworkparted
      if (column.property === 'fworkwhole' || column.property === 'fworkparted') {
        this.tdgzDetailSettings.fmodel = row.fmodel
        this.tdgzDetailSettings.fdetailModal = true
        await this.getTdgzBodyData()
        await this.getTdgzHeadData()
      }
      // 特定刀具 fcutter
      if (column.property === 'fcutter') {
        this.tddjDetailSettings.fmodel = row.fmodel
        this.tddjDetailSettings.fdetailModal = true
        await this.getTddjBodyData()
        await this.getTddjHeadData()
      }
      // 直接人工     fzhijierg 直接人工费(合计)
      if (column.property === 'fzhijierg') {
        this.zjrgDetailSettings.fdetailKeyword = row.fmodel
        this.zjrgDetailSettings.fdetailModal = true
        // 弹窗数据
        await this.getZjBodyData()
        await this.getZjHeadData()
      }

      // 海外调试费  fhaiwaitsf
      if (column.property === 'fhaiwaitsf') {
        var beforeVal = event.target.textContent.trim()
        // 置空单元格容器内元素
        event.target.innerHTML = ''
        // 替换成el-input
        const str = `<div class='cell'>
            <div class='el-input'>
              <input type='text' placeholder='请输入内容' class='el-input__inner'>
            </div>
        </div>`
        cell.innerHTML = str
        //  获取双击后生成的input  根据层级嵌套会有所变化
        const cellInput = cell.children[0].children[0].children[0]
        cellInput.value = Number(beforeVal)
        cellInput.focus() // input自动聚焦
        // "TITLE_PROPER"
        // 失去焦点后  将input移除
        cellInput.onblur = () => {
          const onblurCont = `<div class='cell'>${cellInput.value}</div>`
          // cell.innerHTML = onblurCont // 换成原有的显示内容
          console.log(cellInput.value, ' cellInput.value onblur')
          console.log(cell.innerHTML, ' cell.innerHTML onblur')
          this.$set(cell, 'innerHTML', onblurCont)
          this.$set(row, 'fhaiwaitsf', cellInput.value)
        }
      }
    },
    // 特定刀具 -----------------------------------
    async tddjHandleSizeChange(val) {
      this.tddjDetailSettings.currentPage = 1
      this.tddjDetailSettings.pagesize = val
      await this.getTddjBodyData()
      await this.getTddjHeadData()
    },
    async tddjHandleCurrentChange(val) {
      this.tddjDetailSettings.currentPage = val
      await this.getTddjBodyData()
      await this.getTddjHeadData()
    },
    // 表头数据
    async getTddjHeadData() {
      try {
        this.tddjDetailSettings.fdetailLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey: this.tddjDetailSettings.FRepKey
        })
        this.tddjDetailSettings.fdetailLoading = false
        if (res.Error === 0) {
          if (res.Data.length) {
            this.tddjDetailSettings.detailFormThead = res.Data
          } else {
            this.tddjDetailSettings.detailFormThead = []
          }
        }
        // 机型  功率 生效台数 流水号
        this.tddjDetailSettings.detailFormThead.map(item => {
          this.tddjDetailSettings.fdetailList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        this.tddjDetailSettings.fdetailData = this.tddjDetailSettings.fdetailList.slice()

        // 获取显示表头键值对
        this.tddjDetailSettings.detailFormThead.filter(item => {
          // if (!item.frephide) {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        const listData = this.tddjDetailSettings.fdetailList.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })

        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        // this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.tddjDetailSettings.fdetailLoading = false
      }
    },
    // 表体数据————erp职员列表
    async getTddjBodyData() {
      try {
        this.tddjDetailSettings.fdetailLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.tddjDetailSettings.fdetailKeyword,

          fstatus: '',
          limit: this.tddjDetailSettings.pagesize,
          page: this.tddjDetailSettings.currentPage,
          FRepKey: this.tddjDetailSettings.FRepKey
        })
        this.tddjDetailSettings.fdetailLoading = false

        this.tddjDetailSettings.fdetailList = res.Data
        this.tddjDetailSettings.total = res.total
      } catch (error) {
        this.tddjDetailSettings.fdetailLoading = false
      }
    },

    // 特定工装 特定工装-整体发运 fworkwhole  特定工装-分体发运   fworkparted -----------------------------------
    async tdgzHandleSizeChange(val) {
      this.tdgzDetailSettings.currentPage = 1
      this.tdgzDetailSettings.pagesize = val
      await this.getTdgzBodyData()
      await this.getTdgzHeadData()
    },
    async tdgzHandleCurrentChange(val) {
      this.tdgzDetailSettings.currentPage = val
      await this.getTdgzBodyData()
      await this.getTdgzHeadData()
    },
    // 表头数据
    async getTdgzHeadData() {
      try {
        this.tdgzDetailSettings.fdetailLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey: this.tdgzDetailSettings.FRepKey
        })
        this.tdgzDetailSettings.fdetailLoading = false
        if (res.Error === 0) {
          if (res.Data.length) {
            this.tdgzDetailSettings.detailFormThead = res.Data
          } else {
            this.tdgzDetailSettings.detailFormThead = []
          }
        }
        // 机型  功率 生效台数 流水号
        this.tdgzDetailSettings.detailFormThead.map(item => {
          this.tdgzDetailSettings.fdetailList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        this.tdgzDetailSettings.fdetailData = this.tdgzDetailSettings.fdetailList.slice()

        // 获取显示表头键值对
        this.tdgzDetailSettings.detailFormThead.filter(item => {
          // if (!item.frephide) {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        const listData = this.tdgzDetailSettings.fdetailList.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })

        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        // this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.tdgzDetailSettings.fdetailLoading = false
      }
    },
    // 表体数据————erp职员列表
    async getTdgzBodyData() {
      try {
        this.tdgzDetailSettings.fdetailLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.tdgzDetailSettings.fdetailKeyword,

          fstatus: '',
          limit: this.tdgzDetailSettings.pagesize,
          page: this.tdgzDetailSettings.currentPage,
          FRepKey: this.tdgzDetailSettings.FRepKey
        })
        this.tdgzDetailSettings.fdetailLoading = false

        this.tdgzDetailSettings.fdetailList = res.Data
        this.tdgzDetailSettings.total = res.total
      } catch (error) {
        this.tdgzDetailSettings.fdetailLoading = false
      }
    },
    // 图纸费 -----------------------------------
    async tzfHandleSizeChange(val) {
      this.tzfDetailSettings.currentPage = 1
      this.tzfDetailSettings.pagesize = val
      await this.getTzfBodyData()
      await this.getTzfHeadData()
    },
    async tzfHandleCurrentChange(val) {
      this.tzfDetailSettings.currentPage = val
      await this.getTzfBodyData()
      await this.getTzfHeadData()
    },
    // 表头数据
    async getTzfHeadData() {
      try {
        this.tzfDetailSettings.fdetailLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey: this.tzfDetailSettings.FRepKey
        })
        this.tzfDetailSettings.fdetailLoading = false
        if (res.Error === 0) {
          if (res.Data.length) {
            this.tzfDetailSettings.detailFormThead = res.Data
          } else {
            this.tzfDetailSettings.detailFormThead = []
          }
        }
        // 机型  功率 生效台数 流水号
        this.tzfDetailSettings.detailFormThead.map(item => {
          this.tzfDetailSettings.fdetailList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        this.tzfDetailSettings.fdetailData = this.tzfDetailSettings.fdetailList.slice()

        // 获取显示表头键值对
        this.tzfDetailSettings.detailFormThead.filter(item => {
          // if (!item.frephide) {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        const listData = this.tzfDetailSettings.fdetailList.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })

        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        // this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.tzfDetailSettings.fdetailLoading = false
      }
    },
    // 表体数据————erp职员列表
    async getTzfBodyData() {
      try {
        this.tzfDetailSettings.fdetailLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.tzfDetailSettings.fdetailKeyword,

          fstatus: '',
          limit: this.tzfDetailSettings.pagesize,
          page: this.tzfDetailSettings.currentPage,
          FRepKey: this.tzfDetailSettings.FRepKey
        })
        this.tzfDetailSettings.fdetailLoading = false

        this.tzfDetailSettings.fdetailList = res.Data
        this.tzfDetailSettings.total = res.total
      } catch (error) {
        this.tzfDetailSettings.fdetailLoading = false
      }
    },

    // 委外费用 -----------------------------------
    async wwfyHandleSizeChange(val) {
      this.wwfyDetailSettings.currentPage = 1
      this.wwfyDetailSettings.pagesize = val
      await this.getWwfyBodyData()
      await this.getWwfyHeadData()
    },
    async wwfyHandleCurrentChange(val) {
      this.wwfyDetailSettings.currentPage = val
      await this.getWwfyBodyData()
      await this.getWwfyHeadData()
    },
    // 表头数据
    async getWwfyHeadData() {
      try {
        this.wwfyDetailSettings.fdetailLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey: this.wwfyDetailSettings.FRepKey
        })
        this.wwfyDetailSettings.fdetailLoading = false
        if (res.Error === 0) {
          if (res.Data.length) {
            this.wwfyDetailSettings.detailFormThead = res.Data
          } else {
            this.wwfyDetailSettings.detailFormThead = []
          }
        }
        // 机型  功率 生效台数 流水号
        this.wwfyDetailSettings.detailFormThead.map(item => {
          this.wwfyDetailSettings.fdetailList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        this.wwfyDetailSettings.fdetailData = this.wwfyDetailSettings.fdetailList.slice()

        // 获取显示表头键值对
        this.wwfyDetailSettings.detailFormThead.filter(item => {
          // if (!item.frephide) {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        const listData = this.wwfyDetailSettings.fdetailList.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })

        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        // this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.wwfyDetailSettings.fdetailLoading = false
      }
    },
    // 表体数据————erp职员列表
    async getWwfyBodyData() {
      try {
        this.wwfyDetailSettings.fdetailLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.wwfyDetailSettings.fdetailKeyword,

          fstatus: '',
          limit: this.wwfyDetailSettings.pagesize,
          page: this.wwfyDetailSettings.currentPage,
          FRepKey: this.wwfyDetailSettings.FRepKey
        })
        this.wwfyDetailSettings.fdetailLoading = false

        this.wwfyDetailSettings.fdetailList = res.Data
        this.wwfyDetailSettings.total = res.total
      } catch (error) {
        this.wwfyDetailSettings.fdetailLoading = false
      }
    },
    // 质量成本(交付前) -----------------------------------
    async zlcbHandleSizeChange(val) {
      this.zlcbDetailSettings.currentPage = 1
      this.zlcbDetailSettings.pagesize = val
      await this.getZlcbBodyData()
      await this.getZlcbHeadData()
    },
    async zlcbHandleCurrentChange(val) {
      this.zlcbDetailSettings.currentPage = val
      await this.getZlcbBodyData()
      await this.getZlcbHeadData()
    },
    // 表头数据
    async getZlcbHeadData() {
      try {
        this.zlcbDetailSettings.fdetailLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey: this.zlcbDetailSettings.FRepKey
        })
        this.zlcbDetailSettings.fdetailLoading = false
        if (res.Error === 0) {
          if (res.Data.length) {
            this.zlcbDetailSettings.detailFormThead = res.Data
          } else {
            this.zlcbDetailSettings.detailFormThead = []
          }
        }
        // 机型  功率 生效台数 流水号
        this.zlcbDetailSettings.detailFormThead.map(item => {
          this.zlcbDetailSettings.fdetailList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        this.zlcbDetailSettings.fdetailData = this.zlcbDetailSettings.fdetailList.slice()

        // 获取显示表头键值对
        this.zlcbDetailSettings.detailFormThead.filter(item => {
          // if (!item.frephide) {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        const listData = this.zlcbDetailSettings.fdetailList.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })

        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        // this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.zlcbDetailSettings.fdetailLoading = false
      }
    },
    // 表体数据————erp职员列表
    async getZlcbBodyData() {
      try {
        this.zlcbDetailSettings.fdetailLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.zlcbDetailSettings.fdetailKeyword,

          fstatus: '',
          limit: this.zlcbDetailSettings.pagesize,
          page: this.zlcbDetailSettings.currentPage,
          FRepKey: this.zlcbDetailSettings.FRepKey
        })
        this.zlcbDetailSettings.fdetailLoading = false

        this.zlcbDetailSettings.fdetailList = res.Data
        this.zlcbDetailSettings.total = res.total
      } catch (error) {
        this.zlcbDetailSettings.fdetailLoading = false
      }
    },
    // 售后成本 -----------------------------------
    async shHandleSizeChange(val) {
      this.shDetailSettings.currentPage = 1
      this.shDetailSettings.pagesize = val
      await this.getShBodyData()
      await this.getShHeadData()
    },
    async shHandleCurrentChange(val) {
      this.shDetailSettings.currentPage = val
      await this.getShBodyData()
      await this.getShHeadData()
    },
    // 表头数据
    async getShHeadData() {
      try {
        this.shDetailSettings.fdetailLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey: 26012
        })
        this.shDetailSettings.fdetailLoading = false
        if (res.Error === 0) {
          if (res.Data.length) {
            this.shDetailSettings.detailFormThead = res.Data
            // this.shDetailSettings.detailFormThead = Object.keys(res.Data[0])
          } else {
            this.shDetailSettings.detailFormThead = []
          }
        }
        // console.log(this.shDetailSettings.detailFormThead, ' this.shDetailSettings.detailFormThead')
        // 机型  功率 生效台数 流水号
        this.shDetailSettings.detailFormThead.map(item => {
          this.shDetailSettings.fdetailList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        this.shDetailSettings.fdetailData = this.shDetailSettings.fdetailList.slice()

        // 获取显示表头键值对
        this.shDetailSettings.detailFormThead.filter(item => {
          // if (!item.frephide) {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        const listData = this.shDetailSettings.fdetailList.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })

        // console.log(this.shDetailSettings.detailFormThead, ' this.shDetailSettings.detailFormThead')
        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        // this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.shDetailSettings.fdetailLoading = false
      }
    },
    // 表体数据————erp职员列表
    async getShBodyData() {
      try {
        this.shDetailSettings.fdetailLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.shDetailSettings.fdetailKeyword,

          fstatus: '',
          limit: this.shDetailSettings.pagesize,
          page: this.shDetailSettings.currentPage,
          FRepKey: 26012
        })
        this.shDetailSettings.fdetailLoading = false

        this.shDetailSettings.fdetailList = res.Data
        this.shDetailSettings.total = res.total
      } catch (error) {
        this.shDetailSettings.fdetailLoading = false
      }
    },
    // 水电费合计 -----------------------------------
    async sDHandleSizeChange(val) {
      this.sdDetailSettings.currentPage = 1
      this.sdDetailSettings.pagesize = val
      await this.getSdBodyData()
      await this.getSdHeadData()
    },
    async sDHandleCurrentChange(val) {
      this.sdDetailSettings.currentPage = val
      await this.getSdBodyData()
      await this.getSdHeadData()
    },
    // 表头数据
    async getSdHeadData() {
      try {
        this.sdDetailSettings.fdetailLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey: 26011
        })
        this.sdDetailSettings.fdetailLoading = false
        if (res.Error === 0) {
          if (res.Data.length) {
            this.sdDetailSettings.detailFormThead = res.Data
            // this.detailSettings.detailFormThead = Object.keys(res.Data[0])
          } else {
            this.sdDetailSettings.detailFormThead = []
          }
        }
        // console.log(this.sdDetailSettings.detailFormThead, ' this.sdDetailSettings.detailFormThead')
        // 机型  功率 生效台数 流水号
        this.sdDetailSettings.detailFormThead.map(item => {
          this.sdDetailSettings.fdetailList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        this.sdDetailSettings.fdetailData = this.sdDetailSettings.fdetailList.slice()

        // 获取显示表头键值对
        this.sdDetailSettings.detailFormThead.filter(item => {
          // if (!item.frephide) {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        const listData = this.sdDetailSettings.fdetailList.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })

        // console.log(this.sdDetailSettings.detailFormThead, ' this.sdDetailSettings.detailFormThead')
        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        // this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.sdDetailSettings.fdetailLoading = false
      }
    },
    // 表体数据————erp职员列表
    async getSdBodyData() {
      try {
        this.sdDetailSettings.fdetailLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.sdDetailSettings.fdetailKeyword,

          fstatus: '',
          limit: this.sdDetailSettings.pagesize,
          page: this.sdDetailSettings.currentPage,
          FRepKey: 26011
        })
        this.sdDetailSettings.fdetailLoading = false

        this.sdDetailSettings.fdetailList = res.Data
        this.sdDetailSettings.total = res.total
      } catch (error) {
        this.sdDetailSettings.fdetailLoading = false
      }
    },
    // 直接人工费(合计)-----------------------------------
    async zJHandleSizeChange(val) {
      this.zjrgDetailSettings.currentPage = 1
      this.zjrgDetailSettings.pagesize = val
      await this.getZjBodyData()
      await this.getZjHeadData()
    },
    async zJHandleCurrentChange(val) {
      this.zjrgDetailSettings.currentPage = val
      await this.getZjBodyData()
      await this.getZjHeadData()
    },
    // 表头数据
    async getZjHeadData() {
      try {
        this.zjrgDetailSettings.fdetailLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey: 26001
        })
        this.zjrgDetailSettings.fdetailLoading = false
        if (res.Error === 0) {
          if (res.Data.length) {
            this.zjrgDetailSettings.detailFormThead = res.Data
            // this.detailSettings.detailFormThead = Object.keys(res.Data[0])
          } else {
            this.zjrgDetailSettings.detailFormThead = []
          }
        }
        // console.log(this.zjrgDetailSettings.detailFormThead, ' this.zjrgDetailSettings.detailFormThead')
        // 机型  功率 生效台数 流水号
        this.zjrgDetailSettings.detailFormThead.map(item => {
          this.zjrgDetailSettings.fdetailList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        this.zjrgDetailSettings.fdetailData = this.zjrgDetailSettings.fdetailList.slice()

        // 获取显示表头键值对
        this.zjrgDetailSettings.detailFormThead.filter(item => {
          // if (!item.frephide) {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        const listData = this.zjrgDetailSettings.fdetailList.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })

        // console.log(this.zjrgDetailSettings.detailFormThead, ' this.zjrgDetailSettings.detailFormThead')
        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        // this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.zjrgDetailSettings.fdetailLoading = false
      }
    },
    // 表体数据————erp职员列表
    async getZjBodyData() {
      try {
        this.zjrgDetailSettings.fdetailLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.zjrgDetailSettings.fdetailKeyword,

          fstatus: '',
          limit: this.zjrgDetailSettings.pagesize,
          page: this.zjrgDetailSettings.currentPage,
          FRepKey: 26001
        })
        this.zjrgDetailSettings.fdetailLoading = false

        this.zjrgDetailSettings.fdetailList = res.Data
        this.zjrgDetailSettings.total = res.total
      } catch (error) {
        this.zjrgDetailSettings.fdetailLoading = false
      }
    },
    calculate() {
      this.getBodyData()
    },
    searchUser() {
      this.getBodyData()
    },
    // 保存
    async saveWage() {
      if (this.selectedData.length <= 0) {
        this.$message({
          message: '请选中表格记录，再保存',
          type: 'warning'
        })
        return
      }
      try {
        this.listLoading = true
        // const res = await yuSuanCBSave({
        // const res = await QdhtBaojiaSave({
        const res = await JZBaojiaSave({
          db: this.globalDb.db,
          opername,
          FRepKey,
          selectedData: this.selectedData
        })
        this.listLoading = false

        if (res.Error === 0) {
          await this.back()
        }
      } catch (error) {
        this.listLoading = false
        console.log(error)
      }
    },
    back() {
      this.$router.push('/baojiajz/bjjz')
    },

    // 刷新
    refresh() {
      window.location.reload()
    },

    async toDetail(data) {
      this.detailVisible = true
      this.detail = data
    },

    async getAllData() {
      // await this.getBodyData()
      await this.getHeadData()
    },

    selectSettings(val) {
      if (val === 0) {
        this.settings()
      } else if (val === 1) {
        this.dialogSQL()
      }
    },
    settings() {
      this.configModal = true
      this.getTableConfig()
    },

    // 更新数据
    async getUpdateConfigData() {
      await this.getTableConfig()
      await this.getBodyData()
      await this.getHeadData()
    },

    // SQL修改/更新
    async dialogSQL() {
      this.dialogSQLModal = true
      try {
        const res = await apiSql({
          db: this.globalDb.db,
          opername,
          FRepKey
        })

        if (res.Error === 0) {
          this.formSQL.gzsql = res.Data
          this.formSQL.FRepKey = FRepKey
        }
        setTimeout(() => {
          this.$refs['formSQL'].clearValidate()
        })
      } catch (error) {
        // console.log(error)
      }
    },

    confirmSQL() {
      this.$refs['formSQL'].validate(async(valid) => {
        if (valid) {
          try {
            this.formSQL.db = this.globalDb.db
            this.formSQL.opername = opername
            const res = await apiFileSave(this.formSQL)
            if (res.Error === 0) {
              this.dialogSQLModal = false
              this.$message({
                message: res.Message,
                type: 'success'
              })
            } else {
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            // console.log(error)
          }
        } else {
          return false
        }
      })
    },

    async getTableConfig() {
      try {
        this.configLoading = true
        const res = await tableConfig({
          db: this.globalDb.db,
          opername,
          key: FRepKey
        })
        this.configList = res.Data
        this.key = FRepKey
        this.configLoading = false
      } catch (error) {
        this.configLoading = false
      }
    },

    // 表头数据
    async getHeadData() {
      try {
        this.listLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey
        })
        this.listLoading = false
        this.formThead = res.Data
        // this.tableList = []
        this.formThead.map(item => {
          this.tableList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        // this.tableData = this.tableList.slice()

        // 获取显示表头键值对
        this.formThead.filter(item => {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        // const listData = this.tableList.slice()
        // listData.map((item, index) => {
        //   this.listData[index] = {}
        //   this.headerKeys.map(it => {
        //     this.listData[index][it] = item[it]
        //   })
        // })

        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.listLoading = false
      }
    },

    // 表体数据————erp职员列表
    // 表体数据  计算数据
    async getBodyData() {
      try {
        this.listLoading = true
        // const res = await yuSuanCB({
        // const res = await ScQdhtBaojia({
        const res = await JZbaojiadan({

          db: this.globalDb.db,
          keyword: this.keyword,
          opername,
          fbrand: this.fbrand,
          fsheji: this.youqiVal

        })

        if (res.Error === 0) {
          this.isBtn = false
          this.$message({
            message: res.Message,
            type: 'success'
          })
        } else {
          this.$message({
            message: res.Message,
            type: 'warning'
          })
        }
        this.formThead.map(item => {
          res.Data.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        this.tableData = res.Data.slice()

        this.listLoading = false
      } catch (error) {
        this.listLoading = false
        console.log(error)
      }
    },

    selectPeriod(val) {
      this.fzhejiu = getYearYYYY(val)
      // console.log(this.fzhejiu, val, '  this.qjValue')
      // this.searchUser()
    },

    handleSelectionChange(val) {
      this.selectedData = val
    }

  }
}

</script>
<style lang="scss" scoped>
.config-dialog ::v-deep .el-dialog {
  width: 90%;
}
  .config-dialog ::v-deep .el-dialog__body {
    padding: 0 20px;
    height: 600px;
  }

  .cb-set-modal ::v-deep .el-dialog__body {
    max-height: 750px!important;
    overflow: scroll;
  }
  .cb-set-modal ::v-deep .single-select-table thead .el-table-column--selection .cell {
    display: none;
  }
</style>
